package com.chujian.Activities;

import java.text.SimpleDateFormat;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.chujian.Adapter.OrderHistoryDetailSellerAdapter;
import com.chujian.Threads.HttpClientPostThread;
import com.chujian.Utils.Constan;
import com.chujian.Utils.JsonUtil;
import com.chujian.Utils.Util;
import com.chujian.model.FoodList;
import com.chujian.model.Order;
import com.chujian.orderingsystem.R;
import com.mob.tools.gui.Scrollable;
import com.mob.tools.gui.Scrollable.OnScrollListener;

public class OrderPrintActivity extends Activity implements OnScrollListener{
	private TextView mOrderId;
	private TextView mTableName;
	private TextView mOrderTime;
	private TextView mUserPhone;
	private TextView mTotalPrice;
	
	private TextView mTvItemPrice;
	private List<FoodList> mList;
	private Order mOrder;
	private ListView mListView;
	private OrderHistoryDetailSellerAdapter mAdapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.order_print);
		
		Intent intent=getIntent();
		String jsonString=intent.getStringExtra("order");
		initView(jsonString);
		if(mList!=null){
			mAdapter=new OrderHistoryDetailSellerAdapter(mList, this);
			mListView.setAdapter(mAdapter);
		}
		
	}

	private void initView(String jsonString) {
		// TODO Auto-generated method stub
		mOrderId=(TextView) findViewById(R.id.tv_order_current_list_item_id);
		mTableName=(TextView) findViewById(R.id.tv_order_current_list_item_table);
		mOrderTime=(TextView) findViewById(R.id.tv_order_current_list_item_time);
		mUserPhone=(TextView) findViewById(R.id.tv_order_current_list_item_phone);
		mTotalPrice=(TextView) findViewById(R.id.tv_order_current_list_item_price);
		mListView=(ListView) findViewById(R.id.lv_order_history_detail_s);
		
		mTvItemPrice=(TextView) findViewById(R.id.tv_order_current_list_item_price);
		mTvItemPrice.setTextColor(Color.BLACK);
		mOrder =JsonUtil.OrderFromJson(jsonString);
		if(mOrder!=null){
			mList=mOrder.getFoodList();
			
			SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
			long millis=Long.parseLong(mOrder.getOrderTime());
			Log.i("info", millis+"");
			String dateTime = dateFm.format(new java.util.Date(millis));
			
			mOrderId.setText(mOrder.getOrderId());
			mTableName.setText(mOrder.getTableName());
			mOrderTime.setText(dateTime);
			mUserPhone.setText(mOrder.getUserPhone());
			mTotalPrice.setText(mOrder.getTotalPrice()+"元");
			
		}
		
	}

	public void deleteOrder(View v) {
		switch (v.getId()) {
		case R.id.btn_order_history_detail_s_delete:
			// 删除订单按钮
			finish();
			break;
		case R.id.btn_order_history_detail_s_print:
			Util.confirmDialog("提示", "正在打印，请稍后....", OrderPrintActivity.this);
			break;	
		default:
			break;
		}
	}
	public void IbBack(View v) {

		finish();
	}

	@Override
	public void onScrollChanged(Scrollable arg0, int arg1, int arg2, int arg3,
			int arg4) {
		// TODO Auto-generated method stub
		
	}
}
